<?php
/**
 *
 *   User:King
 *   Date:2021/12/9 17:05
 */

namespace app\bank_api\controller;


use app\common\library\Integrate;
use app\common\model\Business;
use app\common\model\NewVoucher as NewVoucherModel;
use app\common\model\NewOrder as NewOrderModel;
use think\Log;

class NewOrder extends Base
{
    protected $noNeedRight = '*';

    public function list()
    {
        $page                   = $this->request->param('page',1);
        $limit                  = $this->request->param('limit',5);
        $business_id            = $this->request->param('business_id');
        $ticket_template_id     = $this->request->param('ticket_template_id');
        $start_time             = $this->request->param('start_time');
        $end_time               = $this->request->param('end_time');

        $staff     = $this->staffinfo;

        $where = [
            'staff_id'=>$staff['id'],
            'status'=>['>',1]
        ];

        if(!empty($business_id))        $where['business_id'] = $business_id;
        if(!empty($ticket_template_id)) $where['voucher_id']  = $ticket_template_id;
       if($start_time > 0 && $end_time > 0){
            $where['createtime'] = ['between',[$start_time,$end_time]];
        }elseif($start_time > 0 && $end_time <= 0){
            $where['createtime']  = ['>=',$start_time];
        }elseif($start_time <= 0 && $end_time > 0){
            $where['createtime']    = ['<=',$end_time];
        }
        //halt($where);
        $list = NewOrderModel::where($where)->order('id desc')->paginate($limit);
        foreach ($list as $value)
        {
            $value->updatetime = date('Y-m-d H:i:s',$value->updatetime);
        }



        $this->success('成功',$list);
    }


    public function info()
    {
        $id = $this->request->param('id');
        $staff     = $this->staffinfo;

        $where = [
            'staff_id'=>$staff['id'],
            'status'=>['>',1],
            'id'=>$id
        ];
        $info = NewOrderModel::where($where)->find();
        if(!$info) $this->error('未查询到数据');
        $this->success('成功',$info);
    }




}
